package com.demomaster.quickcompat.util;

import android.os.Build;
import android.os.Handler;
import android.os.Looper;

import java.util.LinkedHashMap;


public class QuickHandler extends Handler {

    public QuickHandler() {

    }
    public QuickHandler(Looper mainLooper) {
        super(mainLooper);
    }

    LinkedHashMap runableMap = new LinkedHashMap();
    public void removeCallbacks2(Runnable r) {
        super.removeCallbacks(r);
        runableMap.remove(r);
    }
    public void postDelayed2(Runnable r, long delayMillis) {
        super.postDelayed(r,delayMillis);
        runableMap.put(r,1);
    }

    public boolean hasCallbacks2(Runnable runnable){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
           return super.hasCallbacks(runnable);
        }else {
           return runableMap.containsKey(runnable);
        }
    }

    public void removeAllCallbacks(){
        // 移除所有Runnable
        runableMap.clear();
        removeCallbacksAndMessages(null);
    }
}
